<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/9 0009
 * Time: 9:46
 */

namespace app\index\controller;


use think\Controller;

class Register extends Controller
{
    public function index(){
        return view("index");
    }
    public function register(){
        if(request()->post()){
            $data = request()->param();
            if($data['val2'] != $data['val3']){
                return ['state' => -1,'msg' => '两次密码不一致'];
            }
            if(!captcha_check($data['val4'])){
                return ['state' => -2,'msg' => '验证码不正确'];
            }
            $mobile = db("member")->where('mobile',$data['val1'])->find();
            if(!empty($mobile)){
                return ['state' => -4,'msg' => '该手机号已经注册'];
            }
            $param = [
                'mobile' => $data['val1'],
                'password' => md5($data['val2']),
                'nickname' => $data['val5']
            ];
            $res = db("member")->insert($param);
            if($res){
                return ['state' => 200,'msg' => 'success'];
            }else{
                return ['state' => -3,'msg' => 'error'];
            }
        }
    }
    public function agreement(){
        return view("agreement");
    }
}